import axiosInstance from './axiosInstance';

interface GetFavoritesParams {
  page?: number;
  limit?: number;
}

// 获取用户收藏的商品列表
export const getFavorites = async (params?: GetFavoritesParams) => {
  try {
    return await axiosInstance.get('/favorites', { params });
  } catch (error) {
    console.error('Failed to fetch favorite products:', error);
    throw error;
  }
};

// 从收藏中移除商品
export const removeFromFavorites = async (productId: number) => {
  try {
    return await axiosInstance.delete(`/favorites/${productId}`);
  } catch (error) {
    console.error('Failed to remove product from favorites:', error);
    throw error;
  }
};

// 添加商品到收藏
export const addToFavorites = async (productId: number) => {
  try {
    return await axiosInstance.post('/favorites', { productId });
  } catch (error) {
    console.error('Failed to add product to favorites:', error);
    throw error;
  }
};

// 检查商品是否已收藏
export const isFavorite = async (productId: number) => {
  try {
    return await axiosInstance.get(`/favorites/check/${productId}`);
  } catch (error) {
    console.error('Failed to check if product is favorite:', error);
    throw error;
  }
};